﻿Imports System.Text
Imports ajayumi.develop.VBasic.Core.Win
Imports ajayumi.develop.VBasic.Win.Controls

Public Class frmHtmlCode

    Public Sub SetDefaultUrl(ByVal url As String)
        Me.tstxtUrl.Text = url
        Me.Text = String.Format("{0} 网页源码", url)
    End Sub

    Private Sub WebClientEx1_DownloadProgressChanged(ByVal sender As System.Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebClientEx1.DownloadProgressChanged
        Me.pgb.Value = e.ProgressPercentage
    End Sub

    Private Sub WebClientEx1_GetHtmlCodeCompleted(ByVal sender As System.Object, ByVal e As GetHtmlCodeCompletedEventArgs) Handles WebClientEx1.GetHtmlCodeCompleted
        If e.Error IsNot Nothing Then
            ControlHelper.SetText(Me.rtxtHtmlCode, e.Error.Message)
        Else
            ControlHelper.SetText(Me.rtxtHtmlCode, e.HtmlCode)
        End If

        Me.pgb.Visible = False
    End Sub

    Private Sub tsbtnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbtnEnter.Click
        Dim _Url As String = GetStandardUrl(Me.tstxtUrl.Text.Trim())
        Me.WebClientEx1.GetHtmlCodeAsync(_Url)
        Me.pgb.Visible = True
        Me.pgb.Value = 0
    End Sub

    Private Sub frmHtmlCode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.tsddlEncode.SelectedIndex = 0
    End Sub

    Private Sub tsddlEncode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsddlEncode.SelectedIndexChanged
        Select Case Me.tsddlEncode.SelectedIndex
            Case 1
                Me.WebClientEx1.HtmlEncode = Encoding.GetEncoding("GB2312")
                Exit Select
            Case 2
                Me.WebClientEx1.HtmlEncode = Encoding.UTF8
                Exit Select
            Case Else
                Me.WebClientEx1.HtmlEncode = Encoding.Default
                Exit Select
        End Select
    End Sub
End Class